<?

// **** page editor page ****

$_crit = 'id_data='.D_SITEWIDE.' AND id_parent=0';


$DATA['config'] = datafetch_array('meta', D_SITEWIDE, 0);
	
switch (action(array('editor_save', 'create_object'))) {

	case 'editor_save':

		if (is_array($d = postdata('config'))) {

			dataset('db_delete', tb('data'), $_crit);

			$_data = array();
			foreach ($d as $t => $v)
				if (($t = trim($t)) && ($v = trim($v)))
					$_data[] = array('id_data' => D_SITEWIDE, 'id_parent' => 0, 'name' => $t, 'value' => $v); 
					
			dataset('db_insert', tb('data'), $_data);


			header("Location: "._transformURL($CURRENT->url, array('step_back' => 1)));
			exit;

		}	
		break;
		
	case 'create_object':
		if (($t = trim(postdata('title'))) && ($v = trim(postdata('text')))) {
			dataset('db_insert', tb('data'), 
				array('id_data' => D_SITEWIDE, 'id_parent' => 0, 'name' => $t, 'value' => $v)); 
		}
		
		header("Location: ./");
		exit;

		break;
}
		

?>